/**
 * Created by hms on 2020-08-22.
 */
import UserAPI from '../api/user.js'

export const User={
    state:{
        userlist:[],
        user_total_count:0,
        editUserStatus:-1,
        userinfo:[],
    },
    mutations:{
        setUserList(state,data){
            state.userlist=data;
        },
        setTotalCount(state,count){
            state.user_total_count=count;
        },
        setUserInfo(state,info){
            state.userinfo=info;
        },
        setEditUserStatus(state,status){
            state.editUserStatus=status;
        }
    },
    actions:{
        loadUserList(context,data){
            UserAPI.getUserList(data).then(function(response){
                if(response.data.code==1){
                    context.commit('setUserList',response.data.list);
                    context.commit('setTotalCount',response.data.total_count);
                }
            })
        },
        loadUserInfo(context,data){
            UserAPI.getUserInfo(data).then(function(response){
                 if(response.data.code==1){
                     context.commit('setUserInfo',response.data.info);
                 }
            })
        },
        editUser(context,data){
            UserAPI.editUser(data).then(function(response){
                context.commit('setEditUserStatus',response.data.code);
            })
        },
    },
    getters:{
        getUserList:state => {
            return state.userlist;
        },
        getUserTotalCount:state => {
            return state.user_total_count;
        },
        getUserInfo:state => {
            return state.userinfo;
        },
        getEditUserStatus:state =>{
            return state.editUserStatus;
        }

    }
}
